/*==============================================================================
FILE NAME: Figure_C8.do
CREATED: 25 July 2025
==============================================================================*/


/* Set directory if working independently through code
if c(username)=="" { //insert username
	global rootdir "" // insert root path
	global processed_data "$rootdir/processed_data" 
	global figures "$rootdir/output/figures"  // Define global paths for replication package
} 
*/

*** AIR FIGURE ***
// Share of air complaints by incident complaint over time
use "$processed_data/unique_complaints_clean.dta", clear
drop if year < 2005
keep if incident_air == 1
gen COUNT = 1
gen n = 1
collapse (sum) HEALTH PROPERTY OIL_GAS_SHALE OTHER COUNT, by(year)
foreach x in HEALTH PROPERTY OIL_GAS_SHALE OTHER {
gen `x'_SHARE = `x'/COUNT
replace `x'_SHARE = `x'_SHARE*100
}
tsset year
graph set window fontface "Times New Roman"
tsline HEALTH_SHARE PROPERTY_SHARE OIL_GAS_SHALE_SHARE, lwidth(medthick medthick medthick medthick) legend(label(1 "Health") label(2 "Property") label(3 "Oil/Gas/Shale") size(large) pos(6) col(3)) ytitle("Share of Complaints (%)", size(large)) ylab(,labsize(large)) xtitle("Year", size(large)) xlab(2005(1)2019, nogrid ang(45) labsize(large))
graph export "$figures/Figure_C8_Panel_A.pdf", replace

*** WATER FIGURE ***
// Share of water complaints by incident complaint over time
use "$processed_data/unique_complaints_clean.dta", clear
drop if year < 2005
keep if incident_water == 1
gen COUNT = 1
gen n = 1
collapse (sum) HEALTH PROPERTY OIL_GAS_SHALE OTHER COUNT, by(year)
foreach x in HEALTH PROPERTY OIL_GAS_SHALE OTHER {
gen `x'_SHARE = `x'/COUNT
replace `x'_SHARE = `x'_SHARE*100
}
tsset year
graph set window fontface "Times New Roman"
tsline HEALTH_SHARE PROPERTY_SHARE OIL_GAS_SHALE_SHARE, lwidth(medthick medthick medthick medthick) legend(label(1 "Health") label(2 "Property") label(3 "Oil/Gas/Shale") size(large) pos(6) col(3)) ytitle("Share of Complaints (%)", size(large)) ylab(,labsize(large)) xtitle("Year", size(large)) xlab(2005(1)2019, nogrid ang(45) labsize(large))
graph export "$figures/Figure_C8_Panel_B.pdf", replace

*** WASTE FIGURE ***
// Share of waste complaints by incident complaint over time
use "$processed_data/unique_complaints_clean.dta", clear
drop if year < 2005
keep if incident_waste == 1
gen COUNT = 1
gen n = 1
collapse (sum) HEALTH PROPERTY OIL_GAS_SHALE OTHER COUNT, by(year)
foreach x in HEALTH PROPERTY OIL_GAS_SHALE OTHER {
gen `x'_SHARE = `x'/COUNT
replace `x'_SHARE = `x'_SHARE*100
}
tsset year
graph set window fontface "Times New Roman"
tsline HEALTH_SHARE PROPERTY_SHARE OIL_GAS_SHALE_SHARE, lwidth(medthick medthick medthick medthick) legend(label(1 "Health") label(2 "Property") label(3 "Oil/Gas/Shale") size(large) pos(6) col(3)) ytitle("Share of Complaints (%)", size(large)) ylab(,labsize(large)) xtitle("Year", size(large)) xlab(2005(1)2019, nogrid ang(45) labsize(large))
graph export "$figures/Figure_C8_Panel_C.pdf", replace